
import React from 'react';
import { RedoOutlined } from '@ant-design/icons';
import { Button } from 'antd';
import Controller from 'Controller';
import agent from 'server';

/** 刷新按钮 */
export default function RefreshButton() {

    const path = Controller.instance.useMemo(s => s.project.location.join('/'), [])

    const update = React.useCallback(async () => {
        Controller.instance.run(async s => {
            try {
                s.project.currentFileList = (await agent.post('/api/project/queryFolder').send({ path }).over()).body;
            } catch (error) {
                s.project.currentFileList = []
            }
        })
    }, [path])

    const onClick = React.useCallback(async () => {
        update();
    }, [update])

    React.useEffect(() => {
        update();
    }, [update])

    return (
        <Button
            block
            icon={<RedoOutlined />}
            onClick={onClick}
        >
            刷新
        </Button>
    )
}